package com.mdx.api.entity;

import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import javax.persistence.Entity;
import javax.persistence.Id;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.io.Serializable;

/**
 * (MdxUser)实体类
 *
 * @author makejava
 * @since 2021-11-15 17:28:20
 */

@Data
@Entity
public class CommunityUser implements UserDetails ,Serializable{
    private static final long serialVersionUID = -60169267226405941L;
    /**
    * 用户id
    */
    @Id
    private Long userId;
    /**
    * 用户名
    */
    private String userName;
    /**
    * 密码
    */
    private String password;
    /**
    * 昵称
    */
    private String nick;
    /**
    * 手机号
    */
    private String phone;
    /**
    * 电子邮件
    */
    private String email;
    /**
    * 状态 0 启用 1禁用
    */
    private Integer status;
    /**
    * 性别 0 男 1 女
    */
    private Integer sex;
    /**
    * 个人描述
    */
    private String remarks;
    /**
    * 上次登录时间
    */
    private Date lastLoginTime;
    /**
    * 创建时间
    */
    private Date createTime;
    /**
    * 修改时间
    */
    private Date updateTime;

    // 获取权限，这里就用简单的方法
    // 在spring security中，Authorities既可以是ROLE也可以是Authorities
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public String getUsername() {
        return this.userName;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}